/*
 * AskToBuyModel.java
 * business
 *
 * Created by SunDing on 2016/10/13.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.data.model;

import android.graphics.Bitmap;
import android.text.TextUtils;

import com.yidiandao.business.R;
import com.yidiandao.business.constant.Common;
import com.yidiandao.business.constant.Urls;
import com.yidiandao.business.data.OfferEntity;
import com.yidiandao.business.data.bean.Goods;
import com.yidiandao.business.data.net.BaseResponse;
import com.yidiandao.business.data.net.NetBiz;
import com.yidiandao.business.data.net.NetListener;
import com.yidiandao.business.data.net.exception.BizErrorInfo;
import com.yidiandao.business.data.net.exception.NetErrorInfo;
import com.yidiandao.business.data.request.MySendAskDetailHandleRequest;
import com.yidiandao.business.data.request.PagerRequest;
import com.yidiandao.business.data.request.PostedWantToBuyRequest;
import com.yidiandao.business.data.request.SendAskRequest;
import com.yidiandao.business.data.request.UploadLocalOfferImageRequest;
import com.yidiandao.business.data.request.WantBuyOperateRequest;
import com.yidiandao.business.data.response.AskToBuyInfoResponse;
import com.yidiandao.business.data.response.AskToBuyResponse;
import com.yidiandao.business.data.response.PostedWantToBuyResponse;
import com.yidiandao.business.data.response.UploadLicenseResponse;
import com.yidiandao.business.data.response.WantToBuyDetailOfferListResponse;
import com.yidiandao.business.manager.ImageManager;
import com.yidiandao.business.ui.userabout.wanttobuy.post.PostWantToBuyContract;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.Functional;
import com.yidiandao.business.ui.widget.listview.displaylistitem.MyAskToBuyDetailOfferListItem;
import com.yidiandao.business.ui.widget.listview.displaylistitem.MyJoinedAskListItem;
import com.yidiandao.business.ui.widget.listview.displaylistitem.MySendAskListItem;
import com.yidiandao.business.ui.widget.listview.displaylistitem.WantToBuyDetailGoodsListItem;
import com.yidiandao.business.utils.FileUtils;
import com.yidiandao.business.utils.PictureUtils;
import com.yidiandao.business.utils.PreferenceUtils;
import com.yidiandao.business.utils.TimeUtils;
import com.yidiandao.business.utils.UIUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 求购相关
 */
public class AskToBuyModel implements IAskToBuyModel {
    private NetBiz mNetBiz = new NetBiz();
    /*---------------------发布求购信息相关的变量-----------------------------------*/
    private String mName; //求购商品名
    private String mBrand; //求购属性
    private String mNumber; //求购数量
    private String mStyle; //求购求购单位
    private String mLargeScale; //求购联系地址a
    private String mAddress; //求购详细地址
    private String mPhone; //求购电话
    private String mDesc; //求购说明

    private int mPage;

    private List<DisplayListItem> mOfferListItems = new ArrayList<>();
    List<AskToBuyInfoResponse.DataBean.WantBuyListBean> dataLists = new ArrayList<>();

    @Override
    public void getMySendAsk(String tag, boolean isRefresh, final OnOfferListListener listener) {
        if (isRefresh) {
            mPage = 1;
            mOfferListItems.clear();
            dataLists.clear();
        }
        PagerRequest request = new PagerRequest();
        request.setPage(mPage);
        request.setTag(tag);
        request.setPageSize(Common.PAGER_SIZE);
        request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
        request.setUrl(Urls.MY_WANT_BUY_LIST);
        mNetBiz.sendGetRequest(request, AskToBuyInfoResponse.class,
                new NetListener<AskToBuyInfoResponse>() {
                    @Override
                    public void onSuccess(AskToBuyInfoResponse askToBuyResponse) {
                        mPage++;
                        AskToBuyInfoResponse.DataBean data = askToBuyResponse.getData();
                        List<AskToBuyInfoResponse.DataBean.WantBuyListBean> wantBuyList = data.getWantBuyList();
                        List<DisplayListItem> displayListItems = new ArrayList<>();
                        if (wantBuyList != null) {
                            String firstDate = null;
                            AskToBuyInfoResponse.DataBean.WantBuyListBean bean;
                            for (int i = 0; i < wantBuyList.size(); i++) {
                                if (i == 0) {
                                    bean = wantBuyList.get(0);
                                    //当这是第一条数据时
                                    if (dataLists.size() == 0) {
                                        firstDate = TimeUtils.formatMonth(TimeUtils.getAndroidMillis(bean.getAddTime()), true);
                                        bean.setShowTime(true);
                                    } else {
                                        //与上次存储的最后一条对比
                                        firstDate = TimeUtils.formatMonth(TimeUtils.getAndroidMillis(dataLists.get(dataLists.size() - 1).getAddTime()), true);
                                        bean.setShowTime(!TimeUtils.formatMonth(TimeUtils.getAndroidMillis(bean.getAddTime()), true).equals(firstDate));
                                    }
                                } else {
                                    bean = wantBuyList.get(i);
                                    String formatMonth = TimeUtils.formatMonth(TimeUtils.getAndroidMillis(bean.getAddTime()), true);
                                    if (firstDate.equals(formatMonth)) {
                                        bean.setShowTime(false);
                                    } else {
                                        firstDate = formatMonth;
                                        bean.setShowTime(true);
                                    }
                                }
                                dataLists.add(bean);
                                displayListItems.add(new MySendAskListItem(bean));
                            }
                        }
                        mOfferListItems.addAll(displayListItems);

                        if (listener != null)
                            listener.onSuccess(mOfferListItems, displayListItems.size() != 0, askToBuyResponse.hasMoreData());
                    }

                    @Override
                    public boolean onError(NetErrorInfo netErrorInfo) {
                        if (listener != null) {
                            listener.onFailed();
                        }
                        return true;
                    }

                    @Override
                    public boolean onFailed(BizErrorInfo bizErrorInfo) {
                        if (listener != null) {
                            listener.onFailed();
                        }
                        return true;
                    }

                    @Override
                    public void onFinal() {

                    }
                });
    }

    @Override
    public void getMyJoinedAsk(String tag, int page, final OnGetAskDataListener listener) {
        PagerRequest request = new PagerRequest();
        request.setPage(page);
        request.setTag(tag);
        request.setPageSize(Common.PAGER_SIZE);
        request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
        request.setUrl(Urls.MY_JOINED_OFFER_BUY);
        mNetBiz.sendGetRequest(request, AskToBuyResponse.class,
                new NetListener<AskToBuyResponse>() {
                    @Override
                    public void onSuccess(AskToBuyResponse askToBuyResponse) {
                        int total = askToBuyResponse.getPagination().getTotal();
                        AskToBuyResponse.DataBean data = askToBuyResponse.getData();
                        List<AskToBuyResponse.DataBean.WantListBean> wantList = data.getWantList();
                        ArrayList<DisplayListItem> displayListItems = new ArrayList<>();
                        if (wantList != null) {
                            for (int i = 0; i < wantList.size(); i++) {
                                displayListItems.add(new MyJoinedAskListItem(wantList.get(i)));
                            }
                        }
                        if (listener != null) {
                            listener.onSuccess(displayListItems, total);
                        }
                    }

                    @Override
                    public boolean onError(NetErrorInfo netErrorInfo) {
                        if (listener != null) {
                            listener.onFailed();
                        }
                        return true;
                    }

                    @Override
                    public boolean onFailed(BizErrorInfo bizErrorInfo) {
                        if (listener != null) {
                            listener.onFailed();
                        }
                        return true;
                    }

                    @Override
                    public void onFinal() {
                        if (listener != null) {
                            listener.onFinal();
                        }
                    }
                });
    }

    /*--------------------------------------------------------*/
    @Override
    public boolean isFinishInfo(PostWantToBuyContract.View mView) {
        //判断商品名
      /*  mName = mView.getName();
        if (TextUtils.isEmpty(mName)) {
            UIUtils.showToast(UIUtils.getString(R.string.ask_to_buy_hint1));
            return false;
        }
        //判断属性
        mBrand = mView.getBrand();
        if (TextUtils.isEmpty(mBrand)) {
            UIUtils.showToast(UIUtils.getString(R.string.ask_to_buy_hint9));
            return false;
        }
        //判断详细地址
        mAddress = mView.getAddress();
        if (TextUtils.isEmpty(mAddress)) {
            UIUtils.showToast(UIUtils.getString(R.string.ask_to_buy_hint3));
            return false;
        }
        //判断电话
        mPhone = mView.getPhone();
        if (TextUtils.isEmpty(mPhone)) {
            UIUtils.showToast(UIUtils.getString(R.string.ask_to_buy_hint4));
            return false;
        }
        if (!RegexUtils.isPhoneNumber(mPhone)) {
            UIUtils.showToast(UIUtils.getString(R.string.input_right_number));
            return false;
        }*/

        //判断图片
        if (ImageManager.getInstance().getFinalImageList().size() == 0) {
            UIUtils.showToast(UIUtils.getString(R.string.ask_to_buy_hint11));
            return false;
        }
        //判断联系地址
        mLargeScale = mView.getLargeScale();
        if (TextUtils.isEmpty(mLargeScale)) {
            UIUtils.showToast(UIUtils.getString(R.string.ask_to_buy_hint8));
            return false;
        }
        //判断数量
        mNumber = mView.getNumber();
        if (TextUtils.isEmpty(mNumber)) {
            UIUtils.showToast(UIUtils.getString(R.string.ask_to_buy_hint6));
            return false;
        }
        if (Integer.parseInt(mNumber) <= 0) {
            UIUtils.showToast(UIUtils.getString(R.string.ask_to_buy_hint10));
            return false;
        }
        //判断求购单位
        mStyle = mView.getStyle();
        if (TextUtils.isEmpty(mStyle)) {
            UIUtils.showToast(UIUtils.getString(R.string.ask_to_buy_hint7));
            return false;
        }
        //判断求购说明
        mDesc = mView.getDesc();
        if (TextUtils.isEmpty(mDesc)) {
            UIUtils.showToast(UIUtils.getString(R.string.ask_to_buy_hint5));
            return false;
        }
        return true;
    }

    @Override
    public File pressPic(String path) {
        //压缩图片
        Bitmap bm = PictureUtils.getSmallBitmap(path, 480, 800);
        //保存图片
        return FileUtils.saveBitmapFile(bm, "/upload_" + System.currentTimeMillis() + ".jpg");
    }

    @Override
    public void deletePosted(String tag, String wandId, final OnLoadListener listener) {
        PostedWantToBuyRequest request = new PostedWantToBuyRequest();
        request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
        request.setTag(tag);
        request.setWantId(wandId);
        request.setUrl(Urls.DELETE_POSTED);
        mNetBiz.sendGetRequest(request, BaseResponse.class, new NetListener<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse baseResponse) {
                if (listener != null) {
                    listener.onSuccess();
                }
            }

            @Override
            public boolean onError(NetErrorInfo netErrorInfo) {
                if (listener != null) {
                    listener.onFailed();
                }
                return true;
            }

            @Override
            public boolean onFailed(BizErrorInfo bizErrorInfo) {
                if (listener != null) {
                    listener.onFailed();
                }
                return true;
            }

            @Override
            public void onFinal() {
                if (listener != null) {
                    listener.onFinal();
                }
            }
        });
    }

    @Override
    public void acceptPrice(String tag, String id, final OnLoadListener listener) {
        PostedWantToBuyRequest request = new PostedWantToBuyRequest();
        request.setTag(tag);
        request.setOfferId(id);
        request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
        request.setUrl(Urls.ACCEPT_OFFER);
        mNetBiz.sendGetRequest(request, BaseResponse.class, new NetListener<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse baseResponse) {
                if (listener != null) {
                    listener.onSuccess();
                }
            }

            @Override
            public boolean onError(NetErrorInfo netErrorInfo) {
                if (listener != null) {
                    listener.onFailed();
                }
                return true;
            }

            @Override
            public boolean onFailed(BizErrorInfo bizErrorInfo) {
                if (listener != null) {
                    listener.onFailed();
                }
                return true;
            }

            @Override
            public void onFinal() {
                if (listener != null) {
                    listener.onFinal();
                }
            }
        });
    }

    @Override
    public void getPostedData(String tag, String wandId, final OnAccessListener listener) {
        PostedWantToBuyRequest request = new PostedWantToBuyRequest();
        request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
        request.setTag(tag);
        request.setWantId(wandId);
        request.setUrl(Urls.EDIT_WANT_INFO);
        mNetBiz.sendGetRequest(request, PostedWantToBuyResponse.class, new NetListener<PostedWantToBuyResponse>() {
            @Override
            public void onSuccess(PostedWantToBuyResponse postedWantToBuyResponse) {
                if (null != listener) {
                    listener.onSuccess(postedWantToBuyResponse.getData());
                }

            }

            @Override
            public boolean onError(NetErrorInfo netErrorInfo) {
                if (listener != null) {
                    listener.onFailed();
                }
                return true;
            }

            @Override
            public boolean onFailed(BizErrorInfo bizErrorInfo) {
                if (listener != null) {
                    listener.onFailed();
                }
                return true;
            }

            @Override
            public void onFinal() {
                if (listener != null) {
                    listener.onFinal();
                }
            }
        });

    }

    @Override
    public void sendInfo(String tag, String provinceId, String cityId, String districtId,
                         String mTimeMillis, final OnLoadListener listener) {
        SendAskRequest request = new SendAskRequest();
        request.setUrl(Urls.SEND_ASK_TO_BUY);
        request.setTag(tag);
        request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
        request.setName(mName);
        request.setBrand(mBrand);
        request.setNumber(mNumber);
        request.setStyle(mStyle);
        request.setProvince(provinceId);
        request.setCity(cityId);
        request.setDistrict(districtId);
        request.setAddress(mAddress);
        request.setPhone(mPhone);
        request.setDesc(mDesc);
        request.setAlbumId(mTimeMillis);
        mNetBiz.sendPostRequest(request, BaseResponse.class, new NetListener<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse baseResponse) {
                if (listener != null)
                    listener.onSuccess();
            }

            @Override
            public boolean onError(NetErrorInfo netErrorInfo) {
                if (listener != null)
                    listener.onFailed();
                return true;
            }

            @Override
            public boolean onFailed(BizErrorInfo bizErrorInfo) {
                if (listener != null)
                    listener.onFailed();
                return true;
            }

            @Override
            public void onFinal() {
                if (listener != null)
                    listener.onFinal();
            }
        });
    }

    @Override
    public void sendInfoNew(String tag, String picIds, String desc, String provinceId, String cityId, String areaId, String number, String unit, String wantId, final OnLoadListener listener) {
        SendAskRequest request = new SendAskRequest();
        request.setUrl(Urls.PUBLISH_WANT_BUY);
        request.setTag(tag);
        request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
        request.setPictureIds(picIds);
        request.setDesc(desc);
        request.setProvince(provinceId);
        request.setCity(cityId);
        request.setDistrict(areaId);
        request.setNumber(number);
        request.setStyle(unit);
        request.setWantId(wantId);
        mNetBiz.sendPostRequest(request, BaseResponse.class, new NetListener<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse baseResponse) {
                if (listener != null)
                    listener.onSuccess();
            }

            @Override
            public boolean onError(NetErrorInfo netErrorInfo) {
                if (listener != null)
                    listener.onFailed();
                return true;
            }

            @Override
            public boolean onFailed(BizErrorInfo bizErrorInfo) {
                if (listener != null)
                    listener.onFailed();
                return true;
            }

            @Override
            public void onFinal() {
                if (listener != null)
                    listener.onFinal();
            }
        });
    }

    @Override
    public void sendPic(String tag, File file, final OnAccessListener<String> listener) {
        UploadLocalOfferImageRequest request = new UploadLocalOfferImageRequest();
        request.setUrl(Urls.UPLOAD_WANT_BUY_PIC);
        request.setTag(tag);
        request.addUploadFile("picture", file);
        request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
        mNetBiz.uploadFiles(request, UploadLicenseResponse.class,
                new NetListener<UploadLicenseResponse>() {
                    @Override
                    public void onSuccess(UploadLicenseResponse response) {
                        if (listener != null) {
                            listener.onSuccess(response.getData().getPictureId());
                        }
                    }

                    @Override
                    public boolean onError(NetErrorInfo netErrorInfo) {
                        if (listener != null) {
                            listener.onFailed();
                        }
                        return true;
                    }

                    @Override
                    public boolean onFailed(BizErrorInfo bizErrorInfo) {
                        if (listener != null) {
                            listener.onFailed();
                        }
                        return true;
                    }

                    @Override
                    public void onFinal() {
                        if (listener != null) {
                            listener.onFinal();
                        }
                    }
                });
    }
    @Override
    public void sendOrderCertificatePic(String tag, File file, String orderId, final OnLoadListener listener) {
        UploadLocalOfferImageRequest request = new UploadLocalOfferImageRequest();
        request.setUrl(Urls.CERTIFICATE_UPLOAD_PAYIMG);
        request.setTag(tag);
        request.addUploadFile("picture", file);
        request.setOrder_id(orderId);
        request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
        mNetBiz.uploadFiles(request, BaseResponse.class,
                new NetListener<BaseResponse>() {
                    @Override
                    public void onSuccess(BaseResponse response) {
                        if (listener != null) {
                            listener.onSuccess();
                        }
                    }

                    @Override
                    public boolean onError(NetErrorInfo netErrorInfo) {
                        if (listener != null) {
                            listener.onFailed();
                        }
                        return true;
                    }

                    @Override
                    public boolean onFailed(BizErrorInfo bizErrorInfo) {
                        if (listener != null) {
                            listener.onFailed();
                        }
                        return true;
                    }

                    @Override
                    public void onFinal() {
                        if (listener != null) {
                            listener.onFinal();
                        }
                    }
                });
    }

    /* @Override
     public void getAskDetailData(String tag, String wid, final OnGetAskDataListener listener) {
         QueryWantBuyDetailRequest request = new QueryWantBuyDetailRequest();
         request.setTag(tag);
         request.setUrl(Urls.WANT_BUY_INFO);
         request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
         request.setWid(wid);
         mNetBiz.sendGetRequest(request, MySendAskDetailResponse.class,
                 new NetListener<MySendAskDetailResponse>() {
                     @Override
                     public void onSuccess(MySendAskDetailResponse mySendAskDetailResponse) {
                         MySendAskDetailResponse.DataBean data = mySendAskDetailResponse.getData();
                         if (null == data) {
                             return;
                         }
                         MySendAskDetailResponse.DataBean.InfoBean info = data.getInfo();
                         if (null == info) {
                             return;
                         }
                         List<DisplayListItem> displayListItems = new ArrayList<>();
                         //商品信息
                         displayListItems.add(new MySendAskDetailListItem(info));

                         List<MySendAskDetailResponse.DataBean.OfferListBean> offerList =
                                 data.getOfferList();
                         if (null != offerList && offerList.size() != 0) {
                             //标题+
                             //                            displayListItems.add(new
                             // HomeHotTitleListItem(UIUtils.getString(R.string.offer_list)));
                             for (int i = 0; i < offerList.size(); i++) {
                                 MySendAskDetailResponse.DataBean.OfferListBean offerListBean =
                                         offerList.get(i);
                                 //判断是否是供应商报价
                                 if (null != offerListBean.getGoodsName()
                                         || null != offerListBean.getGoodsBrief()) {
                                     displayListItems.add(
                                             new MySendAskDetailAgentPicListItem(offerListBean));
                                 } else {
                                     List<String> list = offerListBean.getInfo();
                                     //添加1-6张图片
                                     for (int j = 0; j < list.size(); j += 3) {
                                         MultiPicBean multiPicBean = new MultiPicBean();
                                         if (j + 2 >= list.size()) {
                                             multiPicBean.setList(list.subList(j, list.size()));
                                         } else {
                                             multiPicBean.setList(list.subList(j, j + 3));
                                         }
                                         multiPicBean.setNeedStatus(j == 0); //只有第一行才需要间距与图标
                                         multiPicBean.setIsAccept(offerListBean.getIsAccept());
                                         displayListItems.add(
                                                 new MySendAskDetailMultiPicListItem(multiPicBean));
                                     }
                                 }
                                 //报价者的信息
                                 displayListItems.add(
                                         new MySendAskDetailUserInfoListItem(offerListBean));
                                 //判断报价的状态 0 初始 1接受  2 拒绝  按钮的状态
                                 displayListItems.add(
                                         new MySendAskDetailAcceptListItem(offerListBean));
                             }
                         }

                         if (listener != null) {
                             listener.onSuccess(displayListItems, 0);
                         }
                     }

                     @Override
                     public boolean onError(NetErrorInfo netErrorInfo) {
                         if (listener != null) {
                             listener.onFailed();
                         }
                         return true;
                     }

                     @Override
                     public boolean onFailed(BizErrorInfo bizErrorInfo) {
                         if (listener != null) {
                             listener.onFailed();
                         }
                         return true;
                     }

                     @Override
                     public void onFinal() {
                         if (listener != null) {
                             listener.onFinal();
                         }
                     }
                 });
     }
 */
    @Override
    public void handleRequest(
            String tag, String id, String isAccept, final OnLoadListener listener) {
        MySendAskDetailHandleRequest request = new MySendAskDetailHandleRequest();
        request.setId(id);
        request.setTag(tag);
        request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
        request.setIsAccept(isAccept);
        request.setUrl(Urls.ACCEPT);
        mNetBiz.sendGetRequest(request, BaseResponse.class, new NetListener<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse baseResponse) {
                if (listener != null) {
                    listener.onSuccess();
                }
            }

            @Override
            public boolean onError(NetErrorInfo netErrorInfo) {
                if (listener != null) {
                    listener.onFailed();
                }
                return true;
            }

            @Override
            public boolean onFailed(BizErrorInfo bizErrorInfo) {
                if (listener != null) {
                    listener.onFailed();
                }
                return true;
            }

            @Override
            public void onFinal() {
                if (listener != null) {
                    listener.onFinal();
                }
            }
        });
    }

    @Override
    public void getAskToBuyOfferList(final boolean isRefreshing, final List<Goods> similarGoodsList, String wantId, String tag, final OnOfferListListener listener) {
        if (isRefreshing) {
            mPage = 1;
        }
        WantBuyOperateRequest request = new WantBuyOperateRequest();
        request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
        request.setUrl(Urls.DETAIL_OFFER_LIST);
        request.setTag(tag);
        request.setWantId(wantId);
        request.setPageSize(Common.PAGER_SIZE);
        request.setPage(mPage);

        mNetBiz.sendGetRequest(request, WantToBuyDetailOfferListResponse.class, new NetListener<WantToBuyDetailOfferListResponse>() {
            @Override
            public void onSuccess(WantToBuyDetailOfferListResponse response) {
                mPage++;
                if (isRefreshing) {
                    mOfferListItems.clear();
                    if (similarGoodsList != null && similarGoodsList.size() != 0) {
                        List<DisplayListItem> similarListItems = Functional.serverToClient(similarGoodsList, new Functional.Processor<Goods, DisplayListItem>() {
                            @Override
                            public DisplayListItem processToClient(Goods goods) {
                                return new WantToBuyDetailGoodsListItem(goods);
                            }
                        });
                        mOfferListItems.addAll(similarListItems);
                    }
                }
                List<OfferEntity> offerList = response.getData().getOfferList();

                List<DisplayListItem> listItems = Functional.serverToClient(offerList, new Functional.Processor<OfferEntity, DisplayListItem>() {
                    @Override
                    public DisplayListItem processToClient(OfferEntity offerEntity) {
                        return new MyAskToBuyDetailOfferListItem(offerEntity);
                    }
                });
                mOfferListItems.addAll(listItems);

                if (listener != null)
                    listener.onSuccess(mOfferListItems, listItems.size() != 0, response.hasMoreData());
            }

            @Override
            public boolean onError(NetErrorInfo netErrorInfo) {
                if (listener != null)
                    listener.onFailed();
                return false;
            }

            @Override
            public boolean onFailed(BizErrorInfo bizErrorInfo) {
                if (listener != null)
                    listener.onFailed();
                return false;
            }

            @Override
            public void onFinal() {

            }
        });
    }
}
